package com.baymax.test.scene.deo

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.SeekBar
import com.baymax.lib.logger.KLog
import com.baymax.test.scene.BaseScene
import com.baymax.test.scene.addButton
import com.baymax.test.scene.addDFView
import com.baymax.test.scene.newSceneFlexContainer
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class TestSeekBarScene : BaseScene() {
    override fun onCreateView(
        p0: LayoutInflater,
        p1: ViewGroup,
        p2: Bundle?
    ): View = p1.newSceneFlexContainer {

        val seekBar = SeekBar(requireSceneContext())
        addDFView(1200, 100, seekBar)
        seekBar.max = 264520
        seekBar.progress = 0
        var job: Job = Job()
        addButton("start timer") {
            job = launch {
                while (job.isActive) {
                    delay(300)
                    seekBar.progress += 1000
                }
            }
        }
        addButton("+3000"){
            seekBar.progress += 3000
        }
        addButton("-3000"){
            seekBar.progress -= 3000
        }

        seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
            override fun onProgressChanged(
                seekBar: SeekBar?,
                progress: Int,
                fromUser: Boolean
            ) {
                KLog.d("Progress", "onProgressChanged: $progress,max=${seekBar?.max}")
            }

            override fun onStartTrackingTouch(seekBar: SeekBar?) {
                println("start track")
            }

            override fun onStopTrackingTouch(seekBar: SeekBar?) {
                println("stop track")
            }

        })


    }
}